package com.eis.thirdsys.connector.parameter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ParameterDefine {
	private Map<String, ParameterElement> elements = new HashMap<String, ParameterElement>();
	
	public List<ParameterElement> getParameterElements() {
		List<ParameterElement> elementList 
			= new ArrayList<ParameterElement>(elements.values());
		
		Collections.sort(elementList, new ParameterComparator());
		
		return elementList;
	}
	
	public void addElement(ParameterElement element) {
		if (element != null) {
			elements.put(element.getName(), element);
		}
	}
	
	public boolean validateElementValue(ParameterElementValue value) {
		ParameterElement element = elements.get(value.getName());
		
		if (element == null) {
			return false;
		} else {
			if (element.getParameterType() == ParameterType.select) {
				List<String> selectValues = element.getSelectValues();
				
				// validate value
				return selectValues.contains(value.getValue());
			} else {
				return true;
			}
		}
	}
}
